package com.chiaching.framwork.core.feign;

import feign.FeignException;

public class ApiAccessException extends FeignException {

    private final DefaultDecoder.ResponseEntity responseEntity;

    public ApiAccessException(String url, String content) {
        super(500,String.format("接口：[%s] 调用异常！ 返回：[%s]", url, content));
        this.responseEntity = DefaultDecoder.ResponseEntity.EMPTY;
    }

    public ApiAccessException(String url, String content, Throwable throwable) {
        super(500,String.format("接口：[%s] 调用异常！ 返回：[%s]", url, content), throwable);
        this.responseEntity = DefaultDecoder.ResponseEntity.EMPTY;
    }

    public ApiAccessException(int status, String message) {
        super(status, message);
        this.responseEntity = DefaultDecoder.ResponseEntity.EMPTY;
    }

    public ApiAccessException(String url, DefaultDecoder.ResponseEntity responseEntity) {
        super(500,String.format("接口：[%s] 调用异常！ " +
                        "返回：[retCode : %s  retData : %s retMsg : %s]",
                url, responseEntity.getRetCode(), responseEntity.getRetData(), responseEntity.getRetMesg()));
        this.responseEntity = responseEntity;
    }

    public String getRetCode() {
        return responseEntity.getRetCode();
    }

    public Object getRetData() {
        return responseEntity.getRetData();
    }

    public String getRetMesg() {
        return responseEntity.getRetMesg();
    }

}
